package com.aps.common.code;

import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

/**
 * @Author nbZhuozh
 *  分类序列编码策略 (工艺编码: PROC-M001-0001)
 * @Date 2025-10-09  09:43
 **/
@Component
public class CategorySequenceStrategy implements CodeGenerationStrategy{

    @Override
    public String generateCode(String prefix, CodeGenerationParameter parameter) {
        Assert.notNull(prefix, "prefix must not be null");
        Assert.notNull(parameter, "parameter must not be null");
        String category = parameter.getCategoryCode();
        Long sequence = parameter.getSequence();
        return String.format("%s-%s-%04d", prefix, category, sequence);
    }

    @Override
    public boolean validateCode(String code) {
        return code != null && code.matches("^[A-Z]{2,}-[A-Z0-9]{1,}-\\d{8}$");
    }

    @Override
    public String getCodePattern() {
        return "前缀 + 分类码 + 序列号(4位)";
    }
}
